<?php

use yii\helpers\Html;
use yii\grid\GridView;
use kartik\widgets\FileInput;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\JjrUserSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '经纪人管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="jjr-user-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('创建经纪人', ['create'], ['class' => 'btn btn-success']) ?>

        <button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
            excel导入
        </button>
        <?= Html::a('excel导出', ['export'], ['class' => 'btn btn-success']) ?>

    </p>
    <!-- Modal -->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <div class="file-loading">
                        <?php // Usage without a model
                        echo '<label class="control-label">Upload Document</label>';
                        echo FileInput::widget([
                            'name' => 'attachment_3',
                            'options' => ['multiple' => false,'dropZoneEnabled'=>false,'maxFileCount'=>1, 'accept'=>'.csv'],
                            'pluginOptions' => [
                                // 异步上传的接口地址设置
                                'uploadUrl' => \yii\helpers\Url::to(['import']),
                                'uploadAsync' => true,]
                        ]); ?>
                    </div>
                    <div id="kartik-file-errors"></div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                    <?= Html::a('下载模板', ['download'], ['class' => 'btn btn-success']) ?>
                </div>
            </div>
        </div>
    </div>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        //'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
//            'openid',
            'mobile',
            'real_name',
            //'nick_name',
            //'password',
            //'avatar_url:url',
            //'gender',
            ['attribute'=>'identity','value'=>function($model){
                if($model['identity']==1){
                    return '自由经纪人';
                }else if($model['identity']==2){
                    return '公司经纪人';
                }

            }],
            'create_time',
            //'update_time',

            [
                'attribute' => 'invitor','label'=>'推荐人'],
            'invite_code',

            [
                'attribute' => 'status',
                'value' => function($model) {//使用匿名函数格式化（参数为当前模型对象），也可以在模型类中定义该方法
                    $status = ['未审核', '已审核','未知'];
                    return $status[$model['status']];
                }
            ],


            //'sender_remark',

            ['class' => 'yii\grid\ActionColumn','template' => '{audit}{view}{update}{delete}','buttons' => [

                'audit' => function ($url,$model, $key) {
                    if($model['status']==1){
                        return Html::a('<span class="glyphicon glyphicon-remove-sign"></span>', $url, ['title'=> '取消审核'] );
                    }else if($model['status']==0){
                        return Html::a('<span class="glyphicon glyphicon-ok-sign"></span>', $url, ['title'=> '审核'] );

                    }



                }

            ],
                'urlCreator' => function ($action, $model, $key, $index) {
                    switch($action)
                    {
                        case 'audit':
                            if($model['status']==0){
                                return \yii\helpers\Url::toRoute('/jjr-user/audit?id='.$model['id']);
                            }else{
                                return \yii\helpers\Url::toRoute('/jjr-user/cancel-audit?id='.$model['id']);
                            }

                            break;
                        case 'update':
                            return \yii\helpers\Url::toRoute('/jjr-user/update?id='.$model['id']);
                            break;
                        case 'delete':
                            return \yii\helpers\Url::toRoute('/jjr-user/delete?id='.$model['id']);
                            break;
                        case 'view':
                            return \yii\helpers\Url::toRoute('/jjr-user/view?id='.$model['id']);
                            break;

                    }

                },

                'header' => '操作',

            ],
        ],
    ]); ?>
</div>

<!-- 定义数据块 -->
<?php $this->beginBlock('test'); ?>
jQuery(document).ready(function() {
highlight_subnav('jjr-user/index'); //子导航高亮
});





<?php $this->endBlock() ?>
<!-- 将数据块 注入到视图中的某个位置 -->
<?php $this->registerJs($this->blocks['test'], \yii\web\View::POS_END); ?>



